package search.kspatial.cn.servlet;

import search.kspatial.cn.pojo.Element;
import search.kspatial.cn.service.ElementService;
import search.kspatial.cn.tool.JsonUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * @author KK
 * @create 2021/11/14 21:41
 */
@WebServlet(name = "/getBookmark",urlPatterns = "/getBookmark")
public class ViewHandler extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ElementService elementService = new ElementService();
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("gbk");
        String method = req.getParameter("method");
        List<Element> all = elementService.findALLElements();
        HttpSession session = req.getSession();
        session.setAttribute("list", all);
        session.setAttribute("count",1);
        switch (method) {
            case "phoneGetBookmark":
                resp.sendRedirect("phone.jsp");
                break;
            case "picGetBookmark":
                resp.sendRedirect("pc.jsp");
                break;
        }
    }
}
